package com.dyz.swordFingerOffer;

import java.util.ArrayList;
import java.util.Arrays;

public class Multiply66 {
    public static void main(String[] args) {
//        int[] a = new int[]{2,3,4,5,6};
//        int[] arr = new Multiply66().multiply(a);
//        System.out.println(Arrays.toString(arr));
        ArrayList<Character> arr = new ArrayList<>();
        arr.add('1');
        arr.add('2');

        System.out.println(arr.indexOf('1'));
    }

    public int[] multiply(int[] A) {
        //不能使用除法，分两步进行
        //第一个数组保存0到i-1项的乘积
        //第二个数组保存i+1到n-1项的乘积
        int [] res = new int[A.length];
        int size = A.length;
        ArrayList<Integer> arr1 = new ArrayList<>();
        ArrayList<Integer> arr2 = new ArrayList<>();
        int constant1 = 1;
        int constant2 = 1;
        for(int i=0; i<size; i++){
            arr1.add(constant1);
            constant1 *= A[i];
        }

        for(int j= size-1; j>=0;j--){
            arr2.add(constant2);
            constant2*=A[j];
        }
        for(int s = 0; s<size;s++){
            res[s] = arr1.get(s)*arr2.get(size-1-s);
        }

        return res;
    }
}
